/** 
 * Copyright(C) 2010-2011 <webPrj> LTD. All Rights Reserved.                               
 * Project: webPrj
 * Module ID: <0001>
 * Comments: TODO         
 * JDK version used: <JDK1.6.0_25>                              
 * Author: xiamingxing
 * Create Date：10:26:57
 * Modified By: xiamingxing                              
 * Modified Date: 10:26:57                                  
 * Why & What is modified: <修改原因描述>    
 * Version: V1.0                  
 */
package com.xiamx.platform.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	
	/**
	 * 
	 * @description 将字符串转换成日期
	 * @author xiamingxing
	 * @param dateStr
	 * @param format
	 * @return 转换之后的日期
	 */
	public static Date formatStrToDate(String dateStr,String format) {
		Date da = null;
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		try {
			da = sdf.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return da;
	}
	
	/**
	 * 
	 * @description 将日期转换成字符串格式
	 * @author xiamingxing
	 * @param da
	 * @param format
	 * @return 转换字符串后的格式
	 */
	public static String formatDateToStr(Date da , String format) {
		String dateStr = null;
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		if(da != null) {
			dateStr = sdf.format(da);
		}
		return dateStr;
	}
	
	public static void main(String []args) {
		String res = formatDateToStr(new Date(),"yyyyMMdd");
		System.out.println(res);
		Date da = formatStrToDate("2012-06-19 12:24:56","yyyy-MM-dd HH:mm:ss");
		System.out.println(da);
	}

}
